package com.example.demo.client;

import com.example.demo.kiroBot.Same;
import org.json.JSONArray;
import org.json.JSONObject;

public class Data {

    public static String send(String data, String str,int model,String character) {

        JSONObject jsonObject = new JSONObject(data);
        JSONObject send = new JSONObject();
        boolean isGroup = jsonObject.getString("type").equals("group");
        send.put(isGroup ? "group_id" : "user_id", jsonObject.getString("id"));
        JSONArray messageArray = new JSONArray();
        JSONObject messageObject = new JSONObject();
        // 先添加 type
        messageObject.put("type", str);
        // 再添加 data
        JSONObject dataObject = new JSONObject();
        dataObject.put("text", Same.getMessage(jsonObject.getString("msg"),model,character));
        messageObject.put("data", dataObject);
        messageArray.put(messageObject);
        send.put("message", messageArray);
        return send.toString();
    }
    public static String send(String data, String str, String path) {
        JSONObject jsonObject = new JSONObject(data);
        JSONObject send = new JSONObject();
        boolean isGroup = jsonObject.getString("type").equals("group");
        send.put(isGroup ? "group_id" : "user_id", jsonObject.getString("id"));
        JSONArray messageArray = new JSONArray();
        JSONObject messageObject = new JSONObject();
        // 先添加 type
        messageObject.put("type", str);
        // 再添加 data
        JSONObject dataObject = new JSONObject();
        dataObject.put("file", path);
        messageObject.put("data", dataObject);
        messageArray.put(messageObject);
        send.put("message", messageArray);
        System.out.println(send);
        return send.toString();
    }
    public static String sendMessage(String data, String str,String message) {

        JSONObject jsonObject = new JSONObject(data);
        JSONObject send = new JSONObject();
        boolean isGroup = jsonObject.getString("type").equals("group");
        send.put(isGroup ? "group_id" : "user_id", jsonObject.getString("id"));
        JSONArray messageArray = new JSONArray();
        JSONObject messageObject = new JSONObject();
        // 先添加 type
        messageObject.put("type", str);
        // 再添加 data
        JSONObject dataObject = new JSONObject();
        dataObject.put("text",message);
        messageObject.put("data", dataObject);
        messageArray.put(messageObject);
        send.put("message", messageArray);
        return send.toString();
    }
}
